package com.xzssmk.leisure.x.controller;

import javax.servlet.http.HttpSession;

import com.xzssmk.leisure.x.po.ScenicSpot;
import com.xzssmk.leisure.x.service.ScenicSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xzssmk.leisure.x.po.SysUsr;
import com.xzssmk.leisure.x.service.SysUsrService;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/sysusr")
public class SysUsrController {

    @Autowired
    SysUsrService sysUsrService;

    @Autowired
    ScenicSpotService scenicSpotService;

    @RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ResponseBody
    public String login(String loginname, String loginpassword, HttpSession session) {

        if ("admin".equals(loginname)) {//管理员
            SysUsr sysUsr = sysUsrService.login(loginname, loginpassword);
            if (null == sysUsr)
                return "faliure";
            session.setAttribute("usr", sysUsr);
            return "success";
        } else {//商户
            ScenicSpot scenicSpot = scenicSpotService.login(loginname, loginpassword);
            session.setAttribute("scenicSpot", scenicSpot);
            if (null != scenicSpot) {
                return "scenicSpot";
            }
        }
        return "faliure";
    }

    @RequestMapping(value = "/index.html")
    public String index() {
        return "/index";
    }

    @RequestMapping(value = "/scenicSpotIndex.html")
    public String scenicSpotIndex() {
        return "/scenicSpotIndex";
    }

    @RequestMapping("/scenicLogin.html")
    public String editor() {
        return "TestEditor";
    }

    @RequestMapping(value = "/user-scenicSpot-add.html")
    public ModelAndView addIssuePeriod() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("user-scenicSpot-add");
        return modelAndView;
    }

}
